package com.jx.mlxg.controller;

import com.jx.mlxg.entity.Addresses;
import com.jx.mlxg.service.AddressesService;
import com.jx.mlxg.service.OrdersService;
import com.jx.mlxg.utils.ResponseResult;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/addresses")
public class AddressController {

    @Autowired
    private AddressesService addressService;
    @Resource
    private OrdersService ordersService;

    // POST 请求用于添加地址
    @PostMapping("/add")
    public ResponseResult<?> addAddress(@RequestBody Addresses address) {
        return addressService.addAddress(address);
    }

    // POST 请求用于更新地址
    @PostMapping("/update")
    public ResponseResult<?> updateAddress(@RequestBody Addresses address) {
        return addressService.updateAddress(address);
    }

    // POST 请求用于删除地址
    @PostMapping("/delete/{addressId}")
    public ResponseResult<?> deleteAddress(@PathVariable Integer addressId) {
//        ordersService.getOrderById()
//        addressService.deleteAddress(addressId);
        return ResponseResult.failure("暂不支持删除地址，如果需要删除请微信联系老板");
    }

    // GET 请求用于获取单个地址
    @GetMapping("/{addressId}")
    public ResponseResult<?> getAddressById(@PathVariable String addressId) {
        return addressService.getAddressById(Integer.valueOf(addressId));
    }

    // GET 请求用于获取所有地址
    @GetMapping
    public ResponseResult<?> getAllAddresses() {
        return addressService.getAllAddresses();
    }
}